package com.jcgyl.export.config;

import static org.quartz.JobBuilder.newJob;

import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;

import com.jcgyl.export.task.OrderProcessTask;

public class QuartzConfig {
	public static Scheduler scheduler = null;
	public static Trigger trigger = null;

	public static void StartTask(String name, String group, JobDataMap dataMap) throws SchedulerException {
		// 定义一个JobDetail
		JobDetail job = newJob(OrderProcessTask.class) // 定义Job类为HelloQuartz类，这是真正的执行逻辑所在
				.withIdentity(name, group) // 定义name/group
				// .usingJobData(dataKey, value) // 定义属性
				.usingJobData(dataMap).build();
		// 加入这个调度
		scheduler.scheduleJob(job, trigger);
		// 启动之
		scheduler.start();
	}

	// 暂停任务
	public static void PauseTask(String keyId) throws SchedulerException {
		scheduler.pauseJob(new JobKey(keyId));
	}

	// 终止任务
	public static void CancellableTask(String keyId) {
		try {
			scheduler.interrupt(new JobKey(keyId));
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}